<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<title></title>
<meta name="Generator" content="Cocoa HTML Writer">
<meta name="CocoaVersion" content="949.27">
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #b71716}
p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco}
p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; min-height: 12.0px}
p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #606060}
span.s1 {font: 18.0px Helvetica}
span.s2 {color: #0000ff}
span.s3 {color: #0024b7}
span.s4 {color: #606060}
span.s5 {color: #000000}
span.Apple-tab-span {white-space:pre}
</style>
</head>
<body>
<p class="p1"><span class="s1"><b>MarkovSynth<span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span></b></span><b>First order Markov Chain implementation for audio signals</b></p>
<p class="p2"><br></p>
<p class="p1"><b>MarkovSynth.ar(in, isRecording, waitTime, tableSize)</b></p>
<p class="p2"><br></p>
<p class="p1">MarkovSynth populates a sample to sample transition probability table with its signal input. Each possible sample value in an 16bit signal has its own transition probability table whose size is defined by the "tableSize" argument at creation time. It waits and populates the table for "waitTime" seconds and then starts synthesizing audio by continuously outputting a random value selected from the probability table of the last synthesized sample. Once the end of table is reached for a single sample, its index wraps back to zero and populating continues in this fashion as long as "isRecording" argument is non-zero. The character of the input is mainly defined by the way its input signal changes. So input signals showing little difference in amplitude and periodicity has a similar quality in output. The output becomes less dynamic.</p>
<p class="p2"><br></p>
<p class="p1">If the tableSize is 1, the output is usually a reflection of the input. tableSize of 2 makes some funny blips and blops. When tableSize goes higher, older and older transition values are taken into account and the output changes accordingly. You should be careful with the tableSize as it allocates all the memory for the tables beforehand so it may cause troubles.</p>
<p class="p2"><br></p>
<p class="p1"><b>in</b> - Signal input. Should be a signal between -1 and 1. Higher and lower values are clipped and inserted into table as that.</p>
<p class="p1"><b>isRecording</b> - if non-zero, MarkovSynth populates the internal table with its signal input. (Default: 1)</p>
<p class="p1"><b>waitTime</b> - Defines the wait time of the UGen to start synthesizing the table, in seconds. (Default: 2)</p>
<p class="p1"><b>tableSize</b> - The probability table size for each sample. High values are memory hungry! (Default: 10 samples)</p>
<p class="p2"><br></p>
<p class="p1">You may want to use <a href="Filters/LeakDC.html"><span class="s2">LeakDC</span></a> on its output as the output is offset agnostic, it just selects a past-recorded<span class="Apple-converted-space">  </span>transition value at random.</p>
<p class="p2"><br></p>
<p class="p3">// Table size of 1 reflects the input.</p>
<p class="p4">x = { <span class="s3">MarkovSynth</span>.ar(<span class="s3">SinOsc</span>.ar(), 1, 2, 1); }.play;</p>
<p class="p4">x.free;</p>
<p class="p5"><br></p>
<p class="p3">// Table size of 2, keep it running for a while.</p>
<p class="p4">x = { <span class="s3">MarkovSynth</span>.ar(<span class="s3">SinOsc</span>.ar(), 1, 2, 2); }.play;</p>
<p class="p4">x.free;</p>
<p class="p5"><br></p>
<p class="p3">// Table size of 2, Modulating the amplitude a wee bit...</p>
<p class="p4">x = { <span class="s3">MarkovSynth</span>.ar(<span class="s3">SinOsc</span>.ar() * <span class="s3">LFNoise1</span>.ar(0.1).range(0.9, 1), 1, 2, 2); }.play;</p>
<p class="p4">x.free;</p>
<p class="p5"><br></p>
<p class="p3">// Table size of 3, on a periodic signal. A probabilistic explosion...</p>
<p class="p4">x = { <span class="s3">MarkovSynth</span>.ar(<span class="s3">SinOsc</span>.ar(), 1, 2, 3); }.play;</p>
<p class="p4">x.free;</p>
<p class="p5"><br></p>
<p class="p3">// Table size of 10, on a periodic signal. Another probabilistic explosion...</p>
<p class="p3">// When the transitions of the sine curve is broken, it becomes much noisier</p>
<p class="p3">// than tableSize = 3, because there are more samples in the table to try out.</p>
<p class="p3">// if you wait enough, output may stabilize at some point again.</p>
<p class="p4">x = { <span class="s3">MarkovSynth</span>.ar(<span class="s3">SinOsc</span>.ar(), 1, 2, 10); }.play;</p>
<p class="p4">x.free;</p>
<p class="p5"><br></p>
<p class="p3">// Modulating the frequency and amplitude by hand.</p>
<p class="p4">(</p>
<p class="p4">x = { <span class="s3">Out</span>.ar([0,1], <span class="s3">MarkovSynth</span>.ar(<span class="s3">SinOsc</span>.ar(<span class="s3">MouseY</span>.kr(10, 1000)) * <span class="s3">MouseX</span>.kr(0, 1),<span class="Apple-converted-space"> </span></p>
<p class="p4"><span class="Apple-converted-space">                                   </span>1, 1, 50)); }.play;</p>
<p class="p4">)</p>
<p class="p4">x.free;</p>
<p class="p5"><br></p>
<p class="p3">// Feedbacks and modulation!</p>
<p class="p4">(</p>
<p class="p4"><span class="s3">SynthDef</span>(<span class="s4">"markov"</span>, { <span class="s3">arg</span> recEnable = 1, waitTime = 1;</p>
<p class="p4"><span class="Apple-converted-space">                     </span><span class="s3">var</span> fedIn = <span class="s3">LocalIn</span>.ar(1) * 0.5;</p>
<p class="p4"><span class="Apple-converted-space">                     </span><span class="s3">var</span> mark = <span class="s3">MarkovSynth</span>.ar(fedIn + (<span class="s3">Saw</span>.ar(<span class="s3">MouseY</span>.kr(10, 5000)) * <span class="s3">MouseX</span>.kr(0, 0.5)), recEnable, waitTime, 5);</p>
<p class="p4"><span class="Apple-converted-space">                     </span><span class="s3">LocalOut</span>.ar(mark);</p>
<p class="p4"><span class="Apple-converted-space">                     </span><span class="s3">Out</span>.ar(0, mark.dup); } ).send(s);</p>
<p class="p4">)</p>
<p class="p5"><br></p>
<p class="p6"><span class="s5">x = </span><span class="s3">Synth</span><span class="s5">(</span>"markov"<span class="s5">)</span></p>
<p class="p4">x.free;</p>
</body>
</html>
